import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import swaggerJSDoc from 'swagger-jsdoc'
import fs from 'fs'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const parentDir = dirname(__dirname)

// Swagger options
const swaggerOptions = {
  definition: {
    openapi: '1.0.0',
    info: {
      title: 'Node API',
      version: '1.0.0',
      description: 'Node API',
    },
  },
  apis: [join(parentDir, 'src/routes/api/*.js')]
}

const swaggerSpec = swaggerJSDoc(swaggerOptions)

// Write Swagger spec to a file
const outputPath = join(parentDir, 'swagger/swagger.json')
fs.writeFileSync(outputPath, JSON.stringify(swaggerSpec, null, 2))

console.log(`Swagger file generated at: ${outputPath}`)
